# $Id: PKGBUILD 87556 2013-04-03 08:53:08Z mtorromeo $
# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgbase=python-requests
pkgname=(python-requests python2-requests)
pkgver=1.2.0
pkgrel=1
_libname=requests
pkgdesc="Python HTTP for Humans."
url="http://python-requests.org"
makedepends=('python-distribute' 'python2-distribute')
license=('custom: ISC')
arch=('any')
source=(http://pypi.python.org/packages/source/${_libname:0:1}/$_libname/$_libname-$pkgver.tar.gz
        certs.patch)

build() {
    cd "$srcdir/$_libname-$pkgver"
    patch -p0 -i "$srcdir/certs.patch"
    sed -r 's#(\W|^)requests/cacert\.pem(\W|$)##' -i MANIFEST.in
    rm -f requests/cacert.pem

    rm -rf ../buildpy3; mkdir ../buildpy3
    python setup.py build -b ../buildpy3

    rm -rf ../buildpy2; mkdir ../buildpy2
    python2 setup.py build -b ../buildpy2
    find ../buildpy2 -name \*.py -exec sed -r 's|^#!(.*)python$|#!\1python2|' -i {} +
}

check() {
    cd "$srcdir/$_libname-$pkgver"
    test -f "$(python -m requests.certs)"
}

package_python-requests() {
    depends=(python)


    cd "$srcdir/$_libname-$pkgver"
    rm -rf build; ln -s ../buildpy3 build
    python setup.py install --skip-build -O1 --root="$pkgdir"
    install -m0644 -D "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_python2-requests() {
    depends=(python2)
    optdepends=('python2-grequests: asynchronous requests with gevent'
                'python2-simplejson')

    cd "$srcdir/$_libname-$pkgver"
    rm -rf build; ln -s ../buildpy2 build
    python2 setup.py install --skip-build -O1 --root="$pkgdir"
    install -m0644 -D "LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

sha256sums=('cfa615644ae38efe8423ce9edb23470a4615a9147fa3cea5026afb47c9bb3913'
            '55f8ae9c2a81c65fb2e8d94b23cff58524ddfbb31ea5180219e6a79db2975805')
